package com.wzw.conference.entity;

import com.wzw.conference.exception.ConferenceException;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author wzw
 * @date 2023/3/21
 */

@Data
public class Track {

    private final int number;
    private final List<Session> sessions;


    public Track(int number) {
        this.number = number;
        this.sessions = new ArrayList<>();
    }


    public Session getMorningSession() {
        Optional<Session> session = sessions.stream()
                .filter(ses -> ses.getName().equals(SessionName.MORNING_SESSION)).findAny();
        return session.orElseThrow(() -> new ConferenceException("值不存在"));
    }

    public Session addSession(Session session) {
        sessions.add(session);
        return session;
    }

    public boolean canAddTalk(Talk talk) {
        return this.sessions.stream().filter(it -> it.canAddTalk(talk)).count() > 0;
    }

    public void addTalk(Talk talk) {
        this.sessions.stream().filter(it -> it.canAddTalk(talk)).findFirst().ifPresent(it->it.addTalk(talk));
    }
}
